/***************************************************************************
 *   Copyright (C) 2008 by BogDan Vatra                                    *
 *   bogdan@licentia.eu                                                    *
 *                                                                         *
 *   This program is free software: you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation, either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/
#include <QtCore>
#include <query.h>

#include "parteneriplugin.h"
#include "parteneri.h"
#include "cereparteneri.h"

inline void initMyResource()
{
	Q_INIT_RESOURCE(parteneri);
}

ParteneriPlugin::ParteneriPlugin(QObject *parent):QObject(parent)
{
	initMyResource();

}

KontAMabilWindow * ParteneriPlugin::createWidget(QWidget * parent)
{
	Parteneri * m_widget = new Parteneri(parent);
	m_widget->setObjectName(name());
	return m_widget;
}

QIcon ParteneriPlugin::icon(const QString &)
{
	return QIcon(":/parteneri/parteneri.png");
}

QString ParteneriPlugin::querys()
{
	QFile f(":/parteneri/sql.xml");
	if (!f.open(QIODevice::ReadOnly))
		return QString();
	QString querys=f.readAll();
	f.close();
	return querys;
}

int ParteneriPlugin::order()
{
	return 20;
}

int ParteneriPlugin::menuGroup(const QString &)
{
	return 0;
}

QString ParteneriPlugin::toolTip(const QString &)
{
	return "Actualizare parteneri";
}


bool ParteneriPlugin::add(QWidget * /*parent*/, const QString & addStr, QString * result, qint64 * id)
{
	bool res=false;
 	Parteneri * widget = new Parteneri;//(parent);
	res=widget->addPartener(addStr, result, id);
	delete widget;
	return res;
}

QString ParteneriPlugin::name()
{
	return "parteneri";
}

QString ParteneriPlugin::version()
{
	return "0.1";
}

QString ParteneriPlugin::depends()
{
	return "localitati";
}

QString ParteneriPlugin::recommends()
{
	return "Contabilitate|Gestiune|Salarizare|Car";
}

QString ParteneriPlugin::description(const QString &)
{
	QFile f(":/parteneri/doc.html");
	if (!f.open(QIODevice::ReadOnly))
		return QString();
	QString doc=f.readAll();
	f.close();
	return doc;
}

QStringList ParteneriPlugin::menus()
{
	return QStringList()<<"/Contabilitate/Actualizare Baza/Parteneri"<<"/Gestiune/Actualizare Baza/Parteneri"<<"/Facturare/Actualizare Baza/Parteneri";
}

bool ParteneriPlugin::amAnaliticPentru(QWidget * /*parent*/, const QString & cont, TipCont /*tipCont*/, qint64 & idAnalitic)
{
#warning AICI TREBUIE PRINSE TOATE CAZURILE DE PARTENERI CLIENTI, FURNIZORI, CREDITORI, DEBITORI
	if (cont.left(2)!="40" && cont.left(2)!="41")
		return false;

	CereParteneri d;
	if (-1!=idAnalitic && defaultDatabase()->query("parteneri")->locate("id",idAnalitic,false,false,false))
		d.seteazaTextele();

	if (!d.exec())
		return false;

	idAnalitic=defaultDatabase()->query("parteneri")->value("id").toDouble();

	return true;
}

QString ParteneriPlugin::tipAnalitic()
{
	return "parteneri";
}

bool ParteneriPlugin::unicPeAct()
{
	return true;
}

void ParteneriPlugin::analizaAct()
{
	return;
}

Q_EXPORT_PLUGIN2(parteneriPlugin, ParteneriPlugin);
